package com.finance.rule.computer;

import com.alibaba.fastjson.JSONObject;
import com.finance.base.constant.BaseConstants;
import com.finance.base.enums.MajorTypeEnum;
import com.finance.base.exception.BaseException;
import com.finance.report.bean.pojo.LogisticsData;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

/**
 * 运单号以-n结尾为拖件 其余均为主件
 */
@Component
@Scope("prototype")
public class WaybillNumNonSeperatorAnalyzer implements IMajorAnalyzer ,Serializable {

    private String majorSuffix = "";

    private String separator = "";

    @Override
    public boolean isSingle(LogisticsData logisticsData) {
        return false;
    }


    @Override
    public MajorTypeEnum majorTyeOf(LogisticsData logisticsData) {
        return !logisticsData.getWaybillNum().trim().contains(this.separator) ? MajorTypeEnum.MAJOR:MajorTypeEnum.DRAG;
    }

    @Override
    public List<LogisticsData> getOtherParts(LogisticsData logisticsData) {

        return getLogisticsDataReturn(logisticsData);
    }

    @Override
    public void init(String json) {
        if(!StringUtils.isEmpty(json)) {
            JSONObject jsonObject = JSONObject.parseObject(json);
            separator = jsonObject.getString("separator");
        }else{
            throw  new BaseException(BaseConstants.ERR_INIT_JSON_IS_NULL);
        }

    }

    public List<LogisticsData> getLogisticsDataReturn(LogisticsData logisticsData){
        return null;
    }
}
